﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using ClassesTableAdapters;





/// <summary>
/// Summary description for MyClassesBLL
/// </summary>
/// 

[System.ComponentModel.DataObject]
public class MyClassesBLL
{
    ILE_Global ileGlobal = new ILE_Global();


    private MyClassesTableAdapter _myClassesAdapter = null;
    protected MyClassesTableAdapter MyClassesAdapter
    {
        get
        {
            if (_myClassesAdapter == null)
                _myClassesAdapter = new MyClassesTableAdapter();

            return _myClassesAdapter;
        }
    }

    private CoursesTableAdapter _coursesAdapter = null;
    protected CoursesTableAdapter CoursesAdapter
    {
        get
        {
            if (_coursesAdapter == null)
                _coursesAdapter = new CoursesTableAdapter();

            return _coursesAdapter;
        }
    }

    private Courses_SectionTableAdapter _coursesSectionAdapter = null;
    protected Courses_SectionTableAdapter CoursesSectionsAdapter
    {
        get
        {
            if (_coursesSectionAdapter == null)
                _coursesSectionAdapter = new Courses_SectionTableAdapter();

            return _coursesSectionAdapter;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Select, true)]
    public Classes.MyClassesDataTable GetMyClassesByUserID(int userID)
    {
        try
        {
            return MyClassesAdapter.GetMyClassesByUserID(userID);
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("MyClassesBLL:GetMyClassesByUserID:000 - GetMyClassesByUserID Failed", ex, 3);
            return null;
        }
        
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Insert, true)]
    public bool InsertMyClass(int courseID, int sectionNumber, int userID, string type, int sortOrder)
    {
        return MyClassesAdapter.InsertMyClass(courseID, sectionNumber, userID, type, sortOrder) != 0;
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Update, true)]
    public bool UpdateMyClass(int sortOrder, int courseID, int sectionNumber, int userID)
    {
        return (MyClassesAdapter.UpdateMyClass(sortOrder, courseID, sectionNumber, userID) == 0);
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Delete, true)]
    public bool DeleteMyClass(int courseID, int sectionNumber, int userID)
    {
        try
        {
            bool result = (MyClassesAdapter.DeleteMyClass(courseID, sectionNumber, userID) == 1);
            if (result == false)
            {
                ileGlobal.RecordError("MyClassesBLL.cs:DelteMyClass:001", "Failed to delete a row.", 4);
                return false;
            }
            return true;
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("MyClassesBLL.cs:DelteMyClass:003", ex, 4);
            return false;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Select, false)]
    public bool IsSetup(int userID)
    {
        return (Convert.ToInt32(MyClassesAdapter.GetMyClassesByUserID(userID).Count) >= 1);
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Select, false)]
    public Classes.CoursesDataTable GetCourses(bool getEnabled)
    {
        try
        {
            if (getEnabled)
            {
                return CoursesAdapter.GetCoursesByIsEnabled(true);
            }
            else
            {
                return CoursesAdapter.GetCourses();
            }
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("MyClassesBLL:GetCourses:000 - GetCourses Failed", ex, 3);
            return null;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Select, false)]
    public Classes.CoursesDataTable GetCoursesOrderByTitle(bool getEnabled)
    {
        try
        {
            if (getEnabled)
            {
                return CoursesAdapter.GetCoursesByIsEnabledOrderByTitle(true);
            }
            else
            {
                return CoursesAdapter.GetCoursesOrderByTitle();
            }
        }
        catch (Exception ex)
        {
            ileGlobal.RecordError("MyClassesBLL:GetCoursesOrderByTitle:000 - GetCoursesOrderByTitle Failed", ex, 3);
            return null;
        }
    }

    [System.ComponentModel.DataObjectMethodAttribute
        (System.ComponentModel.DataObjectMethodType.Select, false)]
    public bool IsDuplicated(int courseID, int sectionNumber, int userID)
    {
        return MyClassesAdapter.IsDuplicated(courseID, sectionNumber, userID).ToString() != "0";
    }
}
